package chapter1.fundamentals.exercise;

/**
 * @author quanlinlin on 2018/10/25 23:35.
 * @version 1.0
 */
public class E_14 {

    public static void main(String[] args) {
        System.out.println(lg(8));
        System.out.println(lg(10));
        System.out.println(lg(16));
        System.out.println(lg(17));
    }

    public static int lg(int N) {
        int i = 0;
        while (N > 1) {
            N >>= 1;
            i++;
        }
        return i;
    }

    public static int recurLg(int N) {
        if (N == 1) {
            return 0;
        }
        return 1 + recurLg(N / 2);
    }

    public static int charLg(int N) {
       return Integer.toBinaryString(N).length();
    }
}
